package com.mlh.rest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user")
@Controller
public class BookHandler {

    @RequestMapping(value = "/book/{id}",method = RequestMethod.GET)
    public String getBook(@PathVariable("id")String id){
        System.out.println("查询书籍"+id);
        return "success";
    }

    @PostMapping("/book")
    public String addBook(String bookName){
        System.out.println("书名为"+bookName);
        return "success";
    }

    @RequestMapping(value = "/book/{id}",method = RequestMethod.DELETE)
    public String deleteBook(@PathVariable("id")String id){
        System.out.println("删除书籍"+id);
        //return "success"; [如果 这样返 回会报错 JSPs only permit GET POST or HEAD]
        return "redirect:/user/success"; //请求重定向 被解析成 /springmvc/user/success
    }

    @RequestMapping("/success")
    public String success(){
        return "success";
    }

    @PutMapping(value="/book/{id}")
    public String updateBook (@PathVariable("id") String id) {
        System.out.println("修改书籍id=" + id);
        return "redirect:/user/success";
    }

}
